package cn.iocoder.yudao.module.alipay.controller.app.babyorder;

import cn.iocoder.yudao.module.alipay.controller.app.babyorder.vo.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.alipay.controller.app.babyorder.vo.*;
import cn.iocoder.yudao.module.alipay.dal.dataobject.babyorder.BabyOrderDO;
import cn.iocoder.yudao.module.alipay.convert.babyorder.BabyOrderConvert;
import cn.iocoder.yudao.module.alipay.service.babyorder.BabyOrderService;

@Tag(name = "宝宝起名 - 宝宝起名订单")
@RestController
@RequestMapping("/alipay/baby-order")
@Validated
public class BabyOrderController {

    @Resource
    private BabyOrderService babyOrderService;

    @PostMapping("/create")
    @Operation(summary = "创建宝宝起名订单")
    public CommonResult<Long> createBabyOrder(@Valid @RequestBody BabyOrderCreateReqVO createReqVO) {
        return success(babyOrderService.createBabyOrder(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新宝宝起名订单")
    public CommonResult<Boolean> updateBabyOrder(@Valid @RequestBody BabyOrderUpdateReqVO updateReqVO) {
        babyOrderService.updateBabyOrder(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除宝宝起名订单")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBabyOrder(@RequestParam("id") Long id) {
        babyOrderService.deleteBabyOrder(id);
        return success(true);
    }

    @GetMapping("/getBabyOrderByBuyerId")
    @Operation(summary = "根据buyerId获得宝宝起名订单")
    @Parameter(name = "buyerId", description = "用户id", required = true, example = "1024")
    public CommonResult<List<BabyOrderRespVO>> getBabyOrderByBuyerId(@RequestParam("buyerId") String buyerId) {
        List<BabyOrderDO> babyOrder = babyOrderService.getBabyBuyerId(buyerId);
        return success(BabyOrderConvert.INSTANCE.convertList(babyOrder));
    }

    @GetMapping("/get")
    @Operation(summary = "根据id获得宝宝起名订单")
    @Parameter(name = "id", description = "用户id", required = true, example = "1024")
    public CommonResult<BabyOrderRespVO> getBabyOrder(@RequestParam("id") String id) {
        BabyOrderDO babyOrder = babyOrderService.getBabyOrder(id);
        return success(BabyOrderConvert.INSTANCE.convert(babyOrder));
    }

    @GetMapping("/list")
    @Operation(summary = "根据buyerId获得宝宝起名订单列表")
    @Parameter(name = "buyerId", description = "用户id", required = true, example = "1024,2048")
    public CommonResult<Object> getBabyOrderListByBuyerId(@RequestParam("buyerId") String buyerId) {
        return success(babyOrderService.getBabyOrderListByBuyerId(buyerId));
    }

    @GetMapping("/page")
    @Operation(summary = "获得宝宝起名订单分页")
    public CommonResult<PageResult<BabyOrderRespVO>> getBabyOrderPage(@Valid BabyOrderPageReqVO pageVO) {
        return success(babyOrderService.getBabyOrderPage(pageVO));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出宝宝起名订单 Excel")
    @OperateLog(type = EXPORT)
    public void exportBabyOrderExcel(@Valid BabyOrderExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BabyOrderDO> list = babyOrderService.getBabyOrderList(exportReqVO);
        // 导出 Excel
        List<BabyOrderExcelVO> datas = BabyOrderConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "宝宝起名订单.xls", "数据", BabyOrderExcelVO.class, datas);
    }

    @PostMapping("/getShowStatue")
    @Operation(summary = "展示状态")
    public CommonResult<Integer> getShowStatue() {
        return success(0);
    }


}
